Suche senden
Hochladen
Sysprog 13
•
Als ODP, PDF herunterladen
•
2 gefällt mir
•
609 views
Ahmed Mekkawy
Folgen
session 13 of the system programming course made by eglug
Weniger lesen
Mehr lesen
Technologie
Diashow-Anzeige
Melden
Teilen
Diashow-Anzeige
Melden
Teilen
1 von 23
Jetzt herunterladen
Empfohlen
Npc13
Npc13
vamsitricks
The mighty js_function
The mighty js_function
timotheeg
Php radomize
Php radomize
do_aki
Npc14
Npc14
vamsitricks
Computer networkppt4577
Computer networkppt4577
Thiyagarajan_Billa
OpenBot-Code
OpenBot-Code
Anshuman Dhar
Коварный code type ITGM #9
Коварный code type ITGM #9
Andrey Zakharevich
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Yandex
Empfohlen
Npc13
Npc13
vamsitricks
The mighty js_function
The mighty js_function
timotheeg
Php radomize
Php radomize
do_aki
Npc14
Npc14
vamsitricks
Computer networkppt4577
Computer networkppt4577
Thiyagarajan_Billa
OpenBot-Code
OpenBot-Code
Anshuman Dhar
Коварный code type ITGM #9
Коварный code type ITGM #9
Andrey Zakharevich
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Yandex
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
delimitry
Open bot
Open bot
Anshuman Dhar
R tist
R tist
Atul Uttam
Bluespec @waseda
Bluespec @waseda
Takefumi MIYOSHI
Tgh.pl
Tgh.pl
iskabom
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
Sysprog 14
Sysprog 14
Ahmed Mekkawy
C for Java programmers (part 1)
C for Java programmers (part 1)
Dmitry Zinoviev
Process management
Process management
Utkarsh Kulshrestha
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
CODE BLUE
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
ESET Latinoamérica
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Vincenzo Iozzo
Usp
Usp
preethamnaik92
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
Gps c
Gps c
UD. Berkah Jaya Komputer
Qt Rest Server
Qt Rest Server
Vasiliy Sorokin
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
Pavel Albitsky
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
Iosif Itkin
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
Michael Barker
Embedding perl
Embedding perl
Marian Marinov
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
Ahmed Mekkawy
OpenData for governments
OpenData for governments
Ahmed Mekkawy
Weitere ähnliche Inhalte
Was ist angesagt?
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
delimitry
Open bot
Open bot
Anshuman Dhar
R tist
R tist
Atul Uttam
Bluespec @waseda
Bluespec @waseda
Takefumi MIYOSHI
Tgh.pl
Tgh.pl
iskabom
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Functional Thursday
Sysprog 14
Sysprog 14
Ahmed Mekkawy
C for Java programmers (part 1)
C for Java programmers (part 1)
Dmitry Zinoviev
Process management
Process management
Utkarsh Kulshrestha
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
CODE BLUE
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
ESET Latinoamérica
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Vincenzo Iozzo
Usp
Usp
preethamnaik92
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
Gps c
Gps c
UD. Berkah Jaya Komputer
Qt Rest Server
Qt Rest Server
Vasiliy Sorokin
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
Pavel Albitsky
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
Iosif Itkin
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
Michael Barker
Embedding perl
Embedding perl
Marian Marinov
Was ist angesagt?
(20)
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
Open bot
Open bot
R tist
R tist
Bluespec @waseda
Bluespec @waseda
Tgh.pl
Tgh.pl
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
Sysprog 14
Sysprog 14
C for Java programmers (part 1)
C for Java programmers (part 1)
Process management
Process management
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits by Seok-Ha Lee (wh1ant)
Flashback, el primer malware masivo de sistemas Mac
Flashback, el primer malware masivo de sistemas Mac
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Usp
Usp
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Gps c
Gps c
Qt Rest Server
Qt Rest Server
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
Embedding perl
Embedding perl
Andere mochten auch
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
Ahmed Mekkawy
OpenData for governments
OpenData for governments
Ahmed Mekkawy
Securing Governmental Public Services with Free/Open Source Tools - Egyptian ...
Securing Governmental Public Services with Free/Open Source Tools - Egyptian ...
Ahmed Mekkawy
Infrastructure as a Code
Infrastructure as a Code
Ahmed Mekkawy
Encrypted Traffic in Egypt - an attempt to understand
Encrypted Traffic in Egypt - an attempt to understand
Ahmed Mekkawy
111214 ineco justo_cp_monitoreo_cancunshmii5-eng_v1
111214 ineco justo_cp_monitoreo_cancunshmii5-eng_v1
Justo Carretero
FOSS Enterpreneurship
FOSS Enterpreneurship
Ahmed Mekkawy
Sysprog 7
Sysprog 7
Ahmed Mekkawy
Foss Movement In Egypt
Foss Movement In Egypt
Ahmed Mekkawy
Sysprog 16
Sysprog 16
Ahmed Mekkawy
Sysprog17
Sysprog17
Ahmed Mekkawy
Sysprog 15
Sysprog 15
Ahmed Mekkawy
Sysprog 12
Sysprog 12
Ahmed Mekkawy
Sysprog 10
Sysprog 10
Ahmed Mekkawy
Why Cloud Computing has to go the FOSS way
Why Cloud Computing has to go the FOSS way
Ahmed Mekkawy
Intro to FOSS & using it in development
Intro to FOSS & using it in development
Ahmed Mekkawy
Sysprog 8
Sysprog 8
Ahmed Mekkawy
Everything is a Game
Everything is a Game
Ahmed Mekkawy
Networking in Gnu/Linux
Networking in Gnu/Linux
Ahmed Mekkawy
Sysprog 11
Sysprog 11
Ahmed Mekkawy
Andere mochten auch
(20)
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
شركة سبيرولا للأنظمة والجمعية المصرية للمصادر المفتوحة
OpenData for governments
OpenData for governments
Securing Governmental Public Services with Free/Open Source Tools - Egyptian ...
Securing Governmental Public Services with Free/Open Source Tools - Egyptian ...
Infrastructure as a Code
Infrastructure as a Code
Encrypted Traffic in Egypt - an attempt to understand
Encrypted Traffic in Egypt - an attempt to understand
111214 ineco justo_cp_monitoreo_cancunshmii5-eng_v1
111214 ineco justo_cp_monitoreo_cancunshmii5-eng_v1
FOSS Enterpreneurship
FOSS Enterpreneurship
Sysprog 7
Sysprog 7
Foss Movement In Egypt
Foss Movement In Egypt
Sysprog 16
Sysprog 16
Sysprog17
Sysprog17
Sysprog 15
Sysprog 15
Sysprog 12
Sysprog 12
Sysprog 10
Sysprog 10
Why Cloud Computing has to go the FOSS way
Why Cloud Computing has to go the FOSS way
Intro to FOSS & using it in development
Intro to FOSS & using it in development
Sysprog 8
Sysprog 8
Everything is a Game
Everything is a Game
Networking in Gnu/Linux
Networking in Gnu/Linux
Sysprog 11
Sysprog 11
Ähnlich wie Sysprog 13
Sysprog 12
Sysprog 12
Ahmed Mekkawy
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
clarityvision
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
Teddy Hsiung
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
aptcomputerzone
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
aquazac
Introduction to Kernel Programming
Introduction to Kernel Programming
Ahmed Mekkawy
LLVM Backend の紹介
LLVM Backend の紹介
Akira Maruoka
Static analysis of C++ source code
Static analysis of C++ source code
PVS-Studio
Static analysis of C++ source code
Static analysis of C++ source code
Andrey Karpov
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance Evaluation
Emery Berger
Unit 6
Unit 6
siddr
Unit 4
Unit 4
siddr
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
odiliagilby
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
fisher.w.y
Write Python for Speed
Write Python for Speed
Yung-Yu Chen
Osol Pgsql
Osol Pgsql
Emanuel Calvo
Hooking signals and dumping the callstack
Hooking signals and dumping the callstack
Thierry Gayet
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
Platonov Sergey
All I know about rsc.io/c2go
All I know about rsc.io/c2go
Moriyoshi Koizumi
Vcs16
Vcs16
Malikireddy Bramhananda Reddy
Ähnlich wie Sysprog 13
(20)
Sysprog 12
Sysprog 12
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
Introduction to Kernel Programming
Introduction to Kernel Programming
LLVM Backend の紹介
LLVM Backend の紹介
Static analysis of C++ source code
Static analysis of C++ source code
Static analysis of C++ source code
Static analysis of C++ source code
Stabilizer: Statistically Sound Performance Evaluation
Stabilizer: Statistically Sound Performance Evaluation
Unit 6
Unit 6
Unit 4
Unit 4
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
Write Python for Speed
Write Python for Speed
Osol Pgsql
Osol Pgsql
Hooking signals and dumping the callstack
Hooking signals and dumping the callstack
Евгений Крутько, Многопоточные вычисления, современный подход.
Евгений Крутько, Многопоточные вычисления, современный подход.
All I know about rsc.io/c2go
All I know about rsc.io/c2go
Vcs16
Vcs16
Mehr von Ahmed Mekkawy
FOSS, history and philosophy
FOSS, history and philosophy
Ahmed Mekkawy
Virtualization Techniques & Cloud Compting
Virtualization Techniques & Cloud Compting
Ahmed Mekkawy
A look at computer security
A look at computer security
Ahmed Mekkawy
Sysprog 9
Sysprog 9
Ahmed Mekkawy
Sysprog 10
Sysprog 10
Ahmed Mekkawy
Packet Filtering Using Iptables
Packet Filtering Using Iptables
Ahmed Mekkawy
Foss Presentation
Foss Presentation
Ahmed Mekkawy
sysprog3 Part2
sysprog3 Part2
Ahmed Mekkawy
sysprog2 Part2
sysprog2 Part2
Ahmed Mekkawy
Mehr von Ahmed Mekkawy
(9)
FOSS, history and philosophy
FOSS, history and philosophy
Virtualization Techniques & Cloud Compting
Virtualization Techniques & Cloud Compting
A look at computer security
A look at computer security
Sysprog 9
Sysprog 9
Sysprog 10
Sysprog 10
Packet Filtering Using Iptables
Packet Filtering Using Iptables
Foss Presentation
Foss Presentation
sysprog3 Part2
sysprog3 Part2
sysprog2 Part2
sysprog2 Part2
Kürzlich hochgeladen
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Patryk Bandurski
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
XfilesPro
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Katpro Technologies
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Delhi Call girls
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
ThousandEyes
Slack Application Development 101 Slides
Slack Application Development 101 Slides
praypatel2
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
OnBoard
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Sinan KOZAK
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
2toLead Limited
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
LBM Solutions
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Delhi Call girls
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Mark Billinghurst
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Memoori
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
carlostorres15106
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
Kürzlich hochgeladen
(20)
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Slack Application Development 101 Slides
Slack Application Development 101 Slides
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Key Features Of Token Development (1).pptx
Key Features Of Token Development (1).pptx
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Sysprog 13
1.
2.
3.
4.
5.
struct job *jp;
struct nodelist *lp; int pipelen; int prevfd; int pip[2]; prevfd = -1; for (lp = n->npipe.cmdlist; lp; lp = lp->next) { ... pip[1] = -1; if (lp->next) { if (pipe(pip) < 0) { ... } } if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) { ... if (pip[1] >= 0) { close(pip[0]); } if (prevfd > 0) { dup2(prevfd, 0); close(prevfd); } if (pip[1] > 1) { dup2(pip[1], 1); close(pip[1]); } /* Execute */ /* never returns */ } if (prevfd >= 0) close(prevfd); prevfd = pip[0]; close(pip[1]); }
6.
7.
8.
9.
10.
11.
12.
13.
14.
static void ipcsyslog_init(void)
{ if (DEBUG) printf("shmget(%x, %d,...)", (int)KEY_ID, G.shm_size); G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 0644); if (G.shmid == -1) { bb_perror_msg_and_die("shmget"); } G.shbuf = shmat(G.shmid, NULL, 0); if (G.shbuf == (void*) -1L) { /* shmat has bizarre error return */ bb_perror_msg_and_die("shmat"); } memset(G.shbuf, 0, G.shm_size); G.shbuf->size = G.shm_size - offsetof(struct shbuf_ds, data) - 1; /*G.shbuf->tail = 0;*/ // we'll trust the OS to set initial semval to 0 (let's hope) G.s_semid = semget(KEY_ID, 2, IPC_CREAT | IPC_EXCL | 1023); if (G.s_semid == -1) { if (errno == EEXIST) { G.s_semid = semget(KEY_ID, 2, 0); if (G.s_semid != -1) return; } bb_perror_msg_and_die("semget"); } } static void log_to_shmem(const char *msg, int len) { int old_tail, new_tail; if (semop(G.s_semid, G.SMwdn, 3) == -1) { bb_perror_msg_and_die("SMwdn"); } ... /* Circular buffer calculation */ memcpy(G.shbuf->data + old_tail, msg, k); if (semop(G.s_semid, G.SMwup, 1) == -1) { bb_perror_msg_and_die("SMwup"); } } static void ipcsyslog_cleanup(void) { if (G.shmid != -1) { shmdt(G.shbuf); } if (G.shmid != -1) { shmctl(G.shmid, IPC_RMID, NULL); } if (G.s_semid != -1) { semctl(G.s_semid, 0, IPC_RMID, 0); } }
15.
16.
17.
18.
19.
20.
21.
22.
POSIX shm example
int pa_shm_create_rw(pa_shm *m, size_t size, int shared, mode_t mode) { char fn[32]; int fd = -1; struct shm_marker *marker; pa_random(&m->id, sizeof(m->id)); segment_name(fn, sizeof(fn), m->id); if ((fd = shm_open(fn, O_RDWR|O_CREAT|O_EXCL, mode & 0444)) < 0) { ... } m->size = size + PA_ALIGN(sizeof(struct shm_marker)); if (ftruncate(fd, m->size) < 0) { ... } if ((m->ptr = mmap(NULL, m->size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { ... } marker = (struct shm_marker*) ((uint8_t*) m->ptr + m->size - PA_ALIGN(sizeof(struct shm_marker))); pa_atomic_store(&marker->pid, (int) getpid()); pa_atomic_store(&marker->marker, SHM_MARKER); ... m->do_unlink = 1; } void pa_shm_free(pa_shm *m) { ... if (munmap(m->ptr, m->size) < 0) pa_log("munmap() failed: %s", pa_cstrerror(errno)); if (m->do_unlink) { char fn[32]; segment_name(fn, sizeof(fn), m->id); if (shm_unlink(fn) < 0) pa_log(" shm_unlink(%s) failed: %s", fn, pa_cstrerror(errno)); } ... memset(m, 0, sizeof(*m)); } struct shm_marker { pa_atomic_t marker; /* 0xbeefcafe */ pa_atomic_t pid; void *_reserverd1; void *_reserverd2; void *_reserverd3; void *_reserverd4; }; static char *segment_name(char *fn, size_t l, unsigned id) { pa_snprintf(fn, l, "/pulse-shm-%u", id); return fn; }
23.
struct pa_semaphore {
sem_t sem; }; pa_semaphore* pa_semaphore_new(unsigned value) { pa_semaphore *s; s = pa_xnew(pa_semaphore, 1); &s->sem, 0, value); return s; } void pa_semaphore_free(pa_semaphore *s) { sem_destroy(&s->sem) ; } void pa_semaphore_post(pa_semaphore *s) { sem_post(&s->sem) ; } void pa_semaphore_wait(pa_semaphore *s) { int ret; do { ret = sem_wait(&s->sem); } while (ret < 0 && errno == EINTR); } pa_mempool* pa_mempool_new(int shared) { pa_mempool *p; ... p = pa_xnew(pa_mempool, 1); p->semaphore = pa_semaphore_new(0); p->block_size = PA_PAGE_ALIGN(PA_MEMPOOL_SLOT_SIZE); ... if (pa_shm_create_rw(&p->memory, p->n_blocks * p->block_size, shared, 0700) < 0) { } ... return p; } void pa_mempool_free(pa_mempool *p) { ... pa_shm_free(&p->memory); ... pa_semaphore_free(p->semaphore); pa_xfree(p); } static void memblock_wait(pa_memblock *b) { if (pa_atomic_load(&b->n_acquired) > 0) { pa_atomic_inc(&b->please_signal); while (pa_atomic_load(&b->n_acquired) > 0) pa_semaphore_wait(b->pool->semaphore); pa_atomic_dec(&b->please_signal); } } void pa_memblock_release(pa_memblock *b) { int r; r = pa_atomic_dec(&b->n_acquired); pa_assert(r >= 1); if (r == 1 && pa_atomic_load(&b->please_signal)) pa_semaphore_post(b->pool->semaphore); }
Jetzt herunterladen